package cate.common.table.pvp.gradepvp.sheet;

import cate.common.table.ESheet;
import cate.common.table.d.GDGradePvp;
import cate.common.table.pvp.gradepvp.row.GradePvpPrizeRow;
import cate.common.util.random.RWItem;
import cate.common.util.random.RWList;

import java.util.ArrayList;
import java.util.List;

public class GradePvpPrizeSheet extends ESheet<GradePvpPrizeRow> {
    @Override
    public String getSheetName() {
        return "段位赛奖品库";
    }

    public List<String> randomRewardByTypeAndResult(boolean win, int star) {
        int rewardNum = GDGradePvp.COMMON_REWARD_NUM;
        RWList<PrizeRW> rwList = new RWList<>();
        PrizeRW rw;
        for (GradePvpPrizeRow row : this.getList()) {
            if (row.prizeType == (win ? 1 : 2)
                    && row.minStar <= star
                    && star <= row.maxStar) {
                rw = new PrizeRW();
                rw.weight = row.weight;
                rw.rewardStr = row.prizeStr;
                rwList.add(rw);
            }
        }
        List<String> rewards = new ArrayList<>();
        for (int i = 0; i < rewardNum; ++i) {
            rwList.setup();
            PrizeRW row = rwList.get();
            rewards.add(row.rewardStr);
            rwList.list.remove(row);
        }
        return rewards;
    }

    private static final class PrizeRW implements RWItem {
        public double weight;
        public String rewardStr;

        @Override
        public double getWeight() {
            return weight;
        }
    }
}
